# Rect对象的collidepoint()函数来识别哪个按钮被点击了。
import pygame
pygame.init()
white = (255,255,255,255)

font = pygame.font.SysFont("Arial", 16)
text1=font.render(" START ", True, white)
text2=font.render(" PLAY ", True, white)
text3=font.render(" STOP ", True, white)

rect1 = text1.get_rect(topleft=(200,10))
rect2 = text2.get_rect(topleft= (400,10))
rect3 = text3.get_rect(topleft= (600,10))
bg = (127,127,127)
msg=" "
screen = pygame.display.set_mode((800,300))
screen.fill(bg)
running = True
while running:
   for event in pygame.event.get():
      screen.blit(text1, rect1)
      pygame.draw.rect(screen, (255,0,0),rect1,2)
      screen.blit(text2, rect2)
      pygame.draw.rect(screen, (255,0,0),rect2,2)
      screen.blit(text3, rect3)
      pygame.draw.rect(screen, (255,0,0),rect3,2)

      if event.type == pygame.QUIT:
         running = False
      if event.type == pygame.MOUSEBUTTONDOWN:
         if rect1.collidepoint(event.pos):
            msg = "START Button was pressed"
         if rect2.collidepoint(event.pos):
            msg = "PLAY Button was pressed"
         if rect3.collidepoint(event.pos):
            msg = "STOP Button was pressed"
      font = pygame.font.SysFont("Arial", 30)
      img=font.render(msg, True, (0,255,0))
      imgrect=img.get_rect()
      imgrect.center = (400 , 150 )# 设置矩形区域的中心位置:
      pygame.draw.rect(screen, bg, imgrect)  #绘制矩形的边界（可选）:
      screen.blit(img, imgrect)  #将图像绘制到屏幕上:

   pygame.display.update()